import os
import requests
import base64
import time

# Configuration
GPT4V_KEY = "98c7a7e477814840b73f6dad4a1d374e"
IMAGE_PATH = "images/evaluation_deepseekmoe16b_base_1.jpg"
encoded_image = base64.b64encode(open(IMAGE_PATH, 'rb').read()).decode('ascii')
headers = {
    "Content-Type": "application/json",
    "api-key": GPT4V_KEY,
}

# Payload for the request
payload = {
    "messages": [
        {
            "role": "system",
            "content": [
                {
                    "type": "text",
                    "text": "You are an AI assistant that helps people find information."
                },
                {
                    "type": "text",
                    "text": "这张图列举了哪些信息."
                }
            ]
        }
    ],
    "temperature": 0.7,
    "top_p": 0.95,
    "max_tokens": 800
}

GPT4V_ENDPOINT = "https://baichuan.openai.azure.com/openai/deployments/gpt-4-v/chat/completions?api-version=2023-07-01-preview"

start_time = time.time()
# Send request
try:
    response = requests.post(GPT4V_ENDPOINT, headers=headers, json=payload)
    response.raise_for_status()  # Will raise an HTTPError if the HTTP request returned an unsuccessful status code
except requests.RequestException as e:
    raise SystemExit(f"Failed to make the request. Error: {e}")

# Handle the response as needed (e.g., print or process)
print(response.json())
end_time = time.time()
print(end_time - start_time)
